<template>
	<view>
		<PcMineLayout v-if="isPc">
			<PcProject></PcProject>
		</PcMineLayout>
		<block v-else>
			<view class="nav-bar">
				<view class="tabBar-view" style="--number: 3">
					<view class="tabBar-item" :class="{'tabBar-active': !queryData.preStatus}"
						@click="onTabBarEvent('')">
						全部
					</view>
					<view class="tabBar-item" :class="{'tabBar-active': queryData.preStatus == '10'}"
						@click="onTabBarEvent('10')">
						存续中
					</view>
					<view class="tabBar-item" :class="{'tabBar-active': queryData.preStatus == '20'}"
						@click="onTabBarEvent('20')">
						已到期
					</view>
				</view>
			</view>
			<TransactionProject v-for="(item, index) in dataList" :key="index" :item="item"></TransactionProject>
			<Empty v-if="!dataList.length"></Empty>
			<view style="height: 160upx;"></view>
			<FloatTopButton></FloatTopButton>
		</block>
	</view>
</template>

<script>
	import PcProject from './components/PcProject.vue'
	export default {
		components: {
			PcProject
		},
		data() {
			return {
				dataList: [], // 项目列表
				queryData: {
					total: 0,
					pageNo: 1,
					pageSize: 15,
					projectName: '', // 项目名称
					preStatus: '', // 项目运转状态 10存续中 20已到期
				}
			}
		},
		onLoad() {
			this.getProjectMyPage()
		},
		onPullDownRefresh() {
			this.queryData.pageNo = 1
			this.getProjectMyPage()
		},
		onReachBottom() {
			if (this.queryData.total <= this.dataList.length) return
			this.queryData.pageNo += 1
			this.getProjectMyPage()
		},
		methods: {
			/**
			 * 我的项目列表
			 */
			async getProjectMyPage() {
				uni.$util.showLoading()
				const res = await uni.$api.getProjectMyPage(this.queryData).finally(uni.finally)
				const list = res.data.rows || []
				this.queryData.total = res.data.totalRows
				this.dataList = this.queryData.pageNo == 1 ? list : this.dataList.concat(list)
			},
			onTabBarEvent(event) {
				this.queryData.preStatus = event
				this.queryData.pageNo = 1
				this.getProjectMyPage()
			}
		}
	}
</script>

<style scoped lang="scss">
	.nav-bar {
		position: sticky;
		top: 0;
		left: 0;
		z-index: 20;

		.tabBar-view {
			width: 100%;
			height: 76rpx;
			background: #FFFFFF;
			@extend .row-between;

			.tabBar-item {
				width: calc(100% / var(--number));
				height: 100%;
				@extend .column;
				font-size: 27rpx;
				font-weight: 400;
				color: #2C1101;
			}

			.tabBar-active {
				color: #FF2615;
			}
		}
	}
</style>